package com.agent.mapper.provider;

import com.agent.entity.CourseSchedule;
import java.util.List;

/*
    MyBatis 自定义 SQL 提供者类（SQL Provider），通过 Java 代码动态构建 SQL 语句，可用 xml 映射文件替代

 */

public class CourseScheduleBatchSqlProvider {

    // 批量插入课表信息
    public String insertBatch(List<CourseSchedule> list) {
        StringBuilder sql = new StringBuilder();
        sql.append("INSERT INTO course_schedule (user_id, course_name, teacher, location, day_of_week, work_week, start_time, end_time, created_at, updated_at) VALUES ");
        
        for (int i = 0; i < list.size(); i++) {
            if (i > 0) {
                sql.append(",");
            }
            sql.append("(#{list[").append(i).append("].userId},")
               .append("#{list[").append(i).append("].courseName},")
               .append("#{list[").append(i).append("].teacher},")
               .append("#{list[").append(i).append("].location},")
               .append("#{list[").append(i).append("].dayOfWeek},")
               .append("#{list[").append(i).append("].workWeek},")
               .append("#{list[").append(i).append("].startTime},")
               .append("#{list[").append(i).append("].endTime},")
               .append("#{list[").append(i).append("].createdAt},")
               .append("#{list[").append(i).append("].updatedAt})");
        }
        
        return sql.toString();
    }
}
